package com.gjb6.customer.app;

import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;

import com.gjb6.customer.R;
import com.gjb6.customer.account.Login.LoginActivity;
import com.gjb6.customer.app.home.GuideOneFragment;
import com.gjb6.customer.app.home.GuideTwoFragment;
import com.gjb6.customer.app.home.GuiderThreeFragment;
import com.pachong.android.baseuicomponent.activity.BaseActivity;
import com.pachong.android.frameworkbase.customviews.multiviewpager.MultiViewPager;

import butterknife.Bind;
import butterknife.OnClick;

public class MyGuideActivity extends BaseActivity implements ViewPager.OnPageChangeListener {

    @Bind(R.id.btnClick)
    ImageView mBtnClick;
    @Bind(R.id.mvpGuide)
    MultiViewPager mMvpGuide;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        hideToolbar();
        mBtnClick.setVisibility(View.GONE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                    | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
//                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
//            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);
//            window.setNavigationBarColor(Color.TRANSPARENT);
        }
        mMvpGuide.setFragmentManager(getSupportFragmentManager());
        initGuideFragment();
    }

    private void initGuideFragment() {
        GuideOneFragment guideOneFragment = new GuideOneFragment();
        GuideTwoFragment guideTwoFragment = new GuideTwoFragment();
        GuiderThreeFragment guideThreeFragment = new GuiderThreeFragment();

        Fragment[] fragments = new Fragment[]{guideOneFragment, guideTwoFragment, guideThreeFragment};

        for (int i = 0; i < fragments.length; i++) {
            mMvpGuide.add(fragments[i]);
        }
        mMvpGuide.setOnPageChangeListener(this);
    }

    @Override
    public View createDataView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.activity_my_guide, null);
    }


    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        if (position == 2) {
            mBtnClick.setVisibility(View.VISIBLE);
        } else {
            mBtnClick.setVisibility(View.GONE);
        }

    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }

    @OnClick(R.id.btnClick)
    public void onViewClicked() {
        LoginActivity.start(this);
        this.finish();
    }
}
